1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.RecentInfo;
26 
27 private import gio.AppInfoIF;
28 private import gio.IconIF;
29 private import glib.DateTime;
30 private import glib.ErrorG;
31 private import glib.GException;
32 private import glib.Str;
33 private import glib.c.functions;
34 private import gobject.ObjectG;
35 private import gtk.c.functions;
36 public  import gtk.c.types;
37 private import linker.Loader;
38 
39 
40 /**
41  * `GtkRecentInfo` contains the metadata associated with an item in the
42  * recently used files list.
43  */
44 public class RecentInfo
45 {
46 	/** the main Gtk struct */
47 	protected GtkRecentInfo* gtkRecentInfo;
48 	protected bool ownedRef;
49 
50 	/** Get the main Gtk struct */
51 	public GtkRecentInfo* getRecentInfoStruct(bool transferOwnership = false)
52 	{
53 		if (transferOwnership)
54 			ownedRef = false;
55 		return gtkRecentInfo;
56 	}
57 
58 	/** the main Gtk struct as a void* */
59 	protected void* getStruct()
60 	{
61 		return cast(void*)gtkRecentInfo;
62 	}
63 
64 	/**
65 	 * Sets our main struct and passes it to the parent class.
66 	 */
67 	public this (GtkRecentInfo* gtkRecentInfo, bool ownedRef = false)
68 	{
69 		this.gtkRecentInfo = gtkRecentInfo;
70 		this.ownedRef = ownedRef;
71 	}
72 
73 	~this ()
74 	{
75 		if ( Linker.isLoaded(LIBRARY_GTK[0]) && ownedRef )
76 			gtk_recent_info_unref(gtkRecentInfo);
77 	}
78 
79 
80 	/** */
81 	public static GType getType()
82 	{
83 		return gtk_recent_info_get_type();
84 	}
85 
86 	/**
87 	 * Creates a `GAppInfo` for the specified `GtkRecentInfo`
88 	 *
89 	 * In case of error, @error will be set either with a
90 	 * %GTK_RECENT_MANAGER_ERROR or a %G_IO_ERROR
91 	 *
92 	 * Params:
93 	 *     appName = the name of the application that should
94 	 *         be mapped to a `GAppInfo`; if %NULL is used then the default
95 	 *         application for the MIME type is used
96 	 *
97 	 * Returns: the newly created `GAppInfo`
98 	 *
99 	 * Throws: GException on failure.
100 	 */
101 	public AppInfoIF createAppInfo(string appName)
102 	{
103 		GError* err = null;
104 
105 		auto __p = gtk_recent_info_create_app_info(gtkRecentInfo, Str.toStringz(appName), &err);
106 
107 		if (err !is null)
108 		{
109 			throw new GException( new ErrorG(err) );
110 		}
111 
112 		if(__p is null)
113 		{
114 			return null;
115 		}
116 
117 		return ObjectG.getDObject!(AppInfoIF)(cast(GAppInfo*) __p, true);
118 	}
119 
120 	/**
121 	 * Checks whether the resource pointed by @info still exists.
122 	 * At the moment this check is done only on resources pointing
123 	 * to local files.
124 	 *
125 	 * Returns: %TRUE if the resource exists
126 	 */
127 	public bool exists()
128 	{
129 		return gtk_recent_info_exists(gtkRecentInfo) != 0;
130 	}
131 
132 	/**
133 	 * Gets the time when the resource
134 	 * was added to the recently used resources list.
135 	 *
136 	 * Returns: a `GDateTime` for the time
137 	 *     when the resource was added
138 	 */
139 	public DateTime getAdded()
140 	{
141 		auto __p = gtk_recent_info_get_added(gtkRecentInfo);
142 
143 		if(__p is null)
144 		{
145 			return null;
146 		}
147 
148 		return new DateTime(cast(GDateTime*) __p);
149 	}
150 
151 	/**
152 	 * Gets the number of days elapsed since the last update
153 	 * of the resource pointed by @info.
154 	 *
155 	 * Returns: a positive integer containing the number of days
156 	 *     elapsed since the time this resource was last modified
157 	 */
158 	public int getAge()
159 	{
160 		return gtk_recent_info_get_age(gtkRecentInfo);
161 	}
162 
163 	/**
164 	 * Gets the data regarding the application that has registered the resource
165 	 * pointed by @info.
166 	 *
167 	 * If the command line contains any escape characters defined inside the
168 	 * storage specification, they will be expanded.
169 	 *
170 	 * Params:
171 	 *     appName = the name of the application that has registered this item
172 	 *     appExec = return location for the string containing
173 	 *         the command line
174 	 *     count = return location for the number of times this item was registered
175 	 *     stamp = return location for the time this item was last
176 	 *         registered for this application
177 	 *
178 	 * Returns: %TRUE if an application with @app_name has registered this
179 	 *     resource inside the recently used list, or %FALSE otherwise. The
180 	 *     @app_exec string is owned by the `GtkRecentInfo` and should not be
181 	 *     modified or freed
182 	 */
183 	public bool getApplicationInfo(string appName, out string appExec, out uint count, out DateTime stamp)
184 	{
185 		char* outappExec = null;
186 		GDateTime* outstamp = null;
187 
188 		auto __p = gtk_recent_info_get_application_info(gtkRecentInfo, Str.toStringz(appName), &outappExec, &count, &outstamp) != 0;
189 
190 		appExec = Str.toString(outappExec);
191 		stamp = new DateTime(outstamp);
192 
193 		return __p;
194 	}
195 
196 	/**
197 	 * Retrieves the list of applications that have registered this resource.
198 	 *
199 	 * Returns: a newly
200 	 *     allocated %NULL-terminated array of strings. Use g_strfreev() to free it.
201 	 */
202 	public string[] getApplications()
203 	{
204 		size_t length;
205 
206 		auto retStr = gtk_recent_info_get_applications(gtkRecentInfo, &length);
207 
208 		scope(exit) Str.freeStringArray(retStr);
209 		return Str.toStringArray(retStr, length);
210 	}
211 
212 	/**
213 	 * Gets the (short) description of the resource.
214 	 *
215 	 * Returns: the description of the resource. The returned string
216 	 *     is owned by the recent manager, and should not be freed.
217 	 */
218 	public string getDescription()
219 	{
220 		return Str.toString(gtk_recent_info_get_description(gtkRecentInfo));
221 	}
222 
223 	/**
224 	 * Gets the name of the resource.
225 	 *
226 	 * If none has been defined, the basename
227 	 * of the resource is obtained.
228 	 *
229 	 * Returns: the display name of the resource. The returned string
230 	 *     is owned by the recent manager, and should not be freed.
231 	 */
232 	public string getDisplayName()
233 	{
234 		return Str.toString(gtk_recent_info_get_display_name(gtkRecentInfo));
235 	}
236 
237 	/**
238 	 * Retrieves the icon associated to the resource MIME type.
239 	 *
240 	 * Returns: a `GIcon` containing the icon
241 	 */
242 	public IconIF getGicon()
243 	{
244 		auto __p = gtk_recent_info_get_gicon(gtkRecentInfo);
245 
246 		if(__p is null)
247 		{
248 			return null;
249 		}
250 
251 		return ObjectG.getDObject!(IconIF)(cast(GIcon*) __p, true);
252 	}
253 
254 	/**
255 	 * Returns all groups registered for the recently used item @info.
256 	 *
257 	 * The array of returned group names will be %NULL terminated, so
258 	 * length might optionally be %NULL.
259 	 *
260 	 * Returns: a newly allocated %NULL terminated array of strings.
261 	 *     Use g_strfreev() to free it.
262 	 */
263 	public string[] getGroups()
264 	{
265 		size_t length;
266 
267 		auto retStr = gtk_recent_info_get_groups(gtkRecentInfo, &length);
268 
269 		scope(exit) Str.freeStringArray(retStr);
270 		return Str.toStringArray(retStr, length);
271 	}
272 
273 	/**
274 	 * Gets the MIME type of the resource.
275 	 *
276 	 * Returns: the MIME type of the resource. The returned string
277 	 *     is owned by the recent manager, and should not be freed.
278 	 */
279 	public string getMimeType()
280 	{
281 		return Str.toString(gtk_recent_info_get_mime_type(gtkRecentInfo));
282 	}
283 
284 	/**
285 	 * Gets the time when the meta-data
286 	 * for the resource was last modified.
287 	 *
288 	 * Returns: a `GDateTime` for the time
289 	 *     when the resource was last modified
290 	 */
291 	public DateTime getModified()
292 	{
293 		auto __p = gtk_recent_info_get_modified(gtkRecentInfo);
294 
295 		if(__p is null)
296 		{
297 			return null;
298 		}
299 
300 		return new DateTime(cast(GDateTime*) __p);
301 	}
302 
303 	/**
304 	 * Gets the value of the “private” flag.
305 	 *
306 	 * Resources in the recently used list that have this flag
307 	 * set to %TRUE should only be displayed by the applications
308 	 * that have registered them.
309 	 *
310 	 * Returns: %TRUE if the private flag was found, %FALSE otherwise
311 	 */
312 	public bool getPrivateHint()
313 	{
314 		return gtk_recent_info_get_private_hint(gtkRecentInfo) != 0;
315 	}
316 
317 	/**
318 	 * Computes a valid UTF-8 string that can be used as the
319 	 * name of the item in a menu or list.
320 	 *
321 	 * For example, calling this function on an item that refers
322 	 * to “file:///foo/bar.txt” will yield “bar.txt”.
323 	 *
324 	 * Returns: A newly-allocated string in UTF-8 encoding
325 	 *     free it with g_free()
326 	 */
327 	public string getShortName()
328 	{
329 		auto retStr = gtk_recent_info_get_short_name(gtkRecentInfo);
330 
331 		scope(exit) Str.freeString(retStr);
332 		return Str.toString(retStr);
333 	}
334 
335 	/**
336 	 * Gets the URI of the resource.
337 	 *
338 	 * Returns: the URI of the resource. The returned string is
339 	 *     owned by the recent manager, and should not be freed.
340 	 */
341 	public string getUri()
342 	{
343 		return Str.toString(gtk_recent_info_get_uri(gtkRecentInfo));
344 	}
345 
346 	/**
347 	 * Gets a displayable version of the resource’s URI.
348 	 *
349 	 * If the resource is local, it returns a local path; if the
350 	 * resource is not local, it returns the UTF-8 encoded content
351 	 * of [method@Gtk.RecentInfo.get_uri].
352 	 *
353 	 * Returns: a newly allocated UTF-8 string containing the
354 	 *     resource’s URI or %NULL. Use g_free() when done using it.
355 	 */
356 	public string getUriDisplay()
357 	{
358 		auto retStr = gtk_recent_info_get_uri_display(gtkRecentInfo);
359 
360 		scope(exit) Str.freeString(retStr);
361 		return Str.toString(retStr);
362 	}
363 
364 	/**
365 	 * Gets the time when the meta-data
366 	 * for the resource was last visited.
367 	 *
368 	 * Returns: a `GDateTime` for the time
369 	 *     when the resource was last visited
370 	 */
371 	public DateTime getVisited()
372 	{
373 		auto __p = gtk_recent_info_get_visited(gtkRecentInfo);
374 
375 		if(__p is null)
376 		{
377 			return null;
378 		}
379 
380 		return new DateTime(cast(GDateTime*) __p);
381 	}
382 
383 	/**
384 	 * Checks whether an application registered this resource using @app_name.
385 	 *
386 	 * Params:
387 	 *     appName = a string containing an application name
388 	 *
389 	 * Returns: %TRUE if an application with name @app_name was found,
390 	 *     %FALSE otherwise
391 	 */
392 	public bool hasApplication(string appName)
393 	{
394 		return gtk_recent_info_has_application(gtkRecentInfo, Str.toStringz(appName)) != 0;
395 	}
396 
397 	/**
398 	 * Checks whether @group_name appears inside the groups
399 	 * registered for the recently used item @info.
400 	 *
401 	 * Params:
402 	 *     groupName = name of a group
403 	 *
404 	 * Returns: %TRUE if the group was found
405 	 */
406 	public bool hasGroup(string groupName)
407 	{
408 		return gtk_recent_info_has_group(gtkRecentInfo, Str.toStringz(groupName)) != 0;
409 	}
410 
411 	/**
412 	 * Checks whether the resource is local or not by looking at the
413 	 * scheme of its URI.
414 	 *
415 	 * Returns: %TRUE if the resource is local
416 	 */
417 	public bool isLocal()
418 	{
419 		return gtk_recent_info_is_local(gtkRecentInfo) != 0;
420 	}
421 
422 	/**
423 	 * Gets the name of the last application that have registered the
424 	 * recently used resource represented by @info.
425 	 *
426 	 * Returns: an application name. Use g_free() to free it.
427 	 */
428 	public string lastApplication()
429 	{
430 		auto retStr = gtk_recent_info_last_application(gtkRecentInfo);
431 
432 		scope(exit) Str.freeString(retStr);
433 		return Str.toString(retStr);
434 	}
435 
436 	/**
437 	 * Checks whether two `GtkRecentInfo` point to the same resource.
438 	 *
439 	 * Params:
440 	 *     infoB = a `GtkRecentInfo`
441 	 *
442 	 * Returns: %TRUE if both `GtkRecentInfo` point to the same
443 	 *     resource, %FALSE otherwise
444 	 */
445 	public bool match(RecentInfo infoB)
446 	{
447 		return gtk_recent_info_match(gtkRecentInfo, (infoB is null) ? null : infoB.getRecentInfoStruct()) != 0;
448 	}
449 
450 	alias doref = ref_;
451 	/**
452 	 * Increases the reference count of @recent_info by one.
453 	 *
454 	 * Returns: the recent info object with its reference count
455 	 *     increased by one
456 	 */
457 	public RecentInfo ref_()
458 	{
459 		auto __p = gtk_recent_info_ref(gtkRecentInfo);
460 
461 		if(__p is null)
462 		{
463 			return null;
464 		}
465 
466 		return ObjectG.getDObject!(RecentInfo)(cast(GtkRecentInfo*) __p, true);
467 	}
468 
469 	/**
470 	 * Decreases the reference count of @info by one.
471 	 *
472 	 * If the reference count reaches zero, @info is
473 	 * deallocated, and the memory freed.
474 	 */
475 	public void unref()
476 	{
477 		gtk_recent_info_unref(gtkRecentInfo);
478 	}
479 }